package com.zxc.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.zxc.kafka.pojos.User;

import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class KafkaController {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/hello")
    public String onMessage() {
        User user = new User();
        user.setName("小马");
        user.setAge(10);

        kafkaTemplate.send("topic", JSON.toJSONString(user));
        return "ok";
    }

}
